package src.montecarlo;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import src.utils.NormalFunction;
import src.utils.ProbabilityDistributionFunction;

public class SamplingThermalization {

	public static void main(String[] argvs) throws IOException{
	
		int sampleSize;
		
		double delta;
		double eps;
		
		String outputFile;
		
		try {
			sampleSize = new Integer(argvs[0]);
			delta = new Double(argvs[1]);
			eps = new Double(argvs[2]);
			outputFile = argvs[3];
			
		} catch (Exception e) {
			showUsage();
			return;
		}
		
		double mean = 0; double sigma = 1;
		ProbabilityDistributionFunction pdf = new NormalFunction(mean,sigma);
		
		double LOW_BOUNDARY = 0.1;
		double HIGH_BOUNDARY = 0.9;
		
		FileOutputStream fos = new FileOutputStream(new File("therm-results.dat"));
		
		for(double thermalizationTime = LOW_BOUNDARY;thermalizationTime<HIGH_BOUNDARY;thermalizationTime+=eps){
			MetropolisMonteCarlo simulator =  new MetropolisMonteCarlo(pdf,sampleSize,delta,thermalizationTime);
			String sampleTime = (new Integer((int) Math.floor(thermalizationTime*100))).toString();
			simulator.metropolisAlgorithm(outputFile+"-"+sampleTime);
			fos.write((sampleTime+","+outputFile+"-"+sampleTime+"\n").getBytes());
		}
		fos.flush();
		fos.close();
	}
	
	private static void showUsage() {
		
		System.out.println("Usage: ");	
		System.out.println("<sampleSize> <delta> <eps> <outputFile>\n");
		
		System.out.println("<sampleSizew>: Size of the sample.");
		System.out.println("<delta>: step to explore when creating the distribution.");
		System.out.println("<eps>: step size between thermalization ratios.");
		System.out.println("<outputFile>: where to save the results.");
	}
}
